import { selectAllDict } from '@/api/system/dict'

const state = {
  dict: JSON.parse(sessionStorage.getItem('dict'))
}
const mutations = {
  FLUSH_DICT: (state, dict) => {
    sessionStorage.setItem('dict', JSON.stringify(dict))
  }
}
const actions = {
  getDict({ commit }) {
    return new Promise((resolve, reject) => {
      selectAllDict().then(resp => {
        commit('FLUSH_DICT', resp.data)
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
